﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Zeus.Thunder.Core;

namespace SharpTrainer.Xml
{
    class WriteXmlTest1 : ITestCase
    {
        public void Run()
        {
            string path = "Employees.xml";

            try
            {
                using (XmlWriter writer = XmlWriter.Create(path))
                {
                    //Start writing the XML document
                    writer.WriteStartDocument(false);
                    writer.WriteComment("Employee Data");
                    //root
                    writer.WriteStartElement("Employees");

                    /*
                     *  Content of the xml
                     */
                    writer.WriteStartElement("Employee");
                    writer.WriteAttributeString("EmployeeID", "1");
                    writer.WriteElementString("LastName", "Davolio");
                    writer.WriteElementString("FirstName", "Nancy");
                    writer.WriteElementString("Title", "Sales Representative");
                    writer.WriteElementString("City", "Seattle");
                    writer.WriteElementString("Country", "USA");
                    writer.WriteEndElement();
                    
                    writer.WriteEndElement();
                    writer.WriteEndDocument();

                    writer.Flush();
                    Console.WriteLine("Xml: " + path + " write successful!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }
    }
}
